$(function(){
	$.ajax({
		url: urlcore + "/api/callSetting/callSettingDetails",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				var da = data.data;
				if(da!=null){
				$('#thisId').val(da[0].id);
				$("#callTime").val(da[0].callTime);
				$("#person").val(da[0].person);
				$("#type").val(da[0].type);
				}
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}

			} else {
				if (data.msg != '空数据') {
					alert(data.msg)
				}else{
					$('#thiscount').text(0);
				}
			}

		},
		error:function() {
			alert("error");
		}
	});
});

/**
 * 去修改
 */
function toModify(){
	$("#callTime").removeAttr("readonly");
	$("#person").removeAttr("readonly");
	$("#type").removeAttr("disabled");
	$("#modifyRate").css("display","none");
	$("#submitRate").css("display","block");
	alert("开启设置指派！");
}

/**
 * 修改
 */
function subModify() {
	var id = $('#thisId').val();
	var callTime = $('#callTime').val().trim();
	var person = $('#person').val();
	var type = $('#type').val();
	$.ajax({
		url: urlcore + "/api/callSetting/addOrUpdateCallSetting",
		type: "post",
		data: JSON.stringify({
	        "id": id,
	        "callTime": callTime,
	        "person": person,
	        "type": type,
	        "status": 0,
	    }),
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		async: false,
		success:function(data){
			if (data.success == true) {
				$('#thisId').val(data.data.id);
				location.reload();
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}

			} else {
				if (data.msg != '空数据') {
					alert(data.msg)
				}
			}

		},
		error:function() {
			alert("error");
		}
	});
	//系统指派订单
	if(type==1){
		$.ajax({
			url: urlcore + "/api/user/startTask",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			async: false,
			success:function(data){
				if (data.success == true) {
					alert(data.msg);
				} else if (data.code == 'OVERTIME'){
					var thisUrl = window.location.href;
					if (thisUrl.indexOf('login.html') <= -1) {
						top.window.location.href="login.html";
					}
	
				} else {
					if (data.msg != '空数据') {
						alert(data.msg)
					}else{
						$('#thiscount').text(0);
					}
				}
	
			},
			error:function() {
				alert("error");
			}
		});
	}
	if(type==2){
		$.ajax({
			url: urlcore + "/api/user/shutDownTask",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			async: false,
			success:function(data){
				if (data.success == true) {
					alert(data.msg);
				} else if (data.code == 'OVERTIME'){
					var thisUrl = window.location.href;
					if (thisUrl.indexOf('login.html') <= -1) {
						top.window.location.href="login.html";
					}
				} else {
					if (data.msg != '空数据') {
						alert(data.msg)
					}else{
						$('#thiscount').text(0);
					}
				}
	
			},
			error:function() {
				alert("error");
			}
		});
	}
}

